package com.ermao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ermao.mapper.UserMapper;
import com.ermao.pojo.User;
import com.ermao.service.BudgetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Ermao
 * Date: 2021/9/7 21:46
 */
@Service
public class BudgetServiceImpl implements BudgetService {


	private UserMapper userMapper;

	@Autowired
	public void setUserMapper(UserMapper userMapper) {
		this.userMapper = userMapper;
	}

	@Override
	public boolean updateBudget(Integer userId, Integer budgetAmount) {
		User user = new User();
		user.setUserId(userId);
		user.setBudget(budgetAmount);
		return userMapper.updateById(user) > 0;
	}

	@Override
	public User selectBudgetByUserUd(Integer userId) {
		QueryWrapper<User> queryWrapper = new QueryWrapper<>();
		queryWrapper.select("budget").eq("user_id", userId);
		return userMapper.selectOne(queryWrapper);
	}
}
